﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Arizu.Repository;
using System.Data;
using Arizu.Entity;

namespace AiRiZu.User.handler
{
    public class SaveMonthPricing : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.Params["roomId"] == null || string.IsNullOrEmpty(context.Request.Params["roomId"]))
            {
                return;
            }

            try
            {
                long roomId = long.Parse(context.Request.Params["roomId"].ToString());
                int monthlyPricing = int.Parse(context.Request.Params["monthlyPricing"].ToString());
                int additionalMonthlyPricing = int.Parse(context.Request.Params["additionalMonthlyPricing"].ToString());

                AirizuPrice airizuPrice = AirizuPrice.CreateInstance();

                DataTable dt = airizuPrice.GetPrice(roomId);
                if (dt.Rows.Count == 0)
                {
                    PriceEntity entity = new PriceEntity();
                    entity.RoomID = roomId;
                    airizuPrice.Insert(entity);
                }

                airizuPrice.UpdateMonthPricing(roomId, monthlyPricing, additionalMonthlyPricing);


                context.Response.Write("success");
            }
            catch (Exception)
            {

                context.Response.Write("error");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
